package API.Class.File.AutoOpenSoftware;

import API.Class.util.StringPro;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Start {
    public static long GetTime(long beginTime, long endTime) {
        double charter = System.currentTimeMillis() - beginTime;
        BigDecimal bd = null;
        boolean b = false;
        if (charter >= 1000) {
            b = true;
            bd = new BigDecimal(charter);
            bd = bd.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
        }
        return bd.longValue();
    }

    public static String version() {
        return "Auto Open Software(beta-3.72)";
    }

    public String RunSoftware(String[] openPath) throws IOException {
        StringPro str = new StringPro();
        final Runtime runtime = Runtime.getRuntime();
        Process process = null;
        Reader r = null;
        r = new Reader(new File(""));
        openPath = r.Read();
        long beginTime = System.currentTimeMillis();
        boolean exception = false;
        for (int i = 0; i < openPath.length; i++) {
            if (openPath[i].isEmpty())
                continue;
            String filePath = openPath[i];
            File file = new File(filePath);
            if (file.exists()) {
                Desktop.getDesktop().open(file);
                str.appendLn(filePath + "running succeed");
            } else {
                str.appendLn(filePath + "running defeat");
            }
        }
        return str.toString();

    }
}



